package cn.entity;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class User {
	private String userName;
	private String userPasswd;

	private Connection con;
	private PreparedStatement pst;
	private ResultSet rSet;

	private Connection getConnect() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver");
		con = DriverManager.getConnection(
				"jdbc:mysql://localhost:3306/gouwuche?characterEncoding=UTF-8",
				"root", "");
		return con;
	}

	public boolean validate(String name, String passwd) throws SQLException,
			ClassNotFoundException {

		String sql = "select * from common_user where name = ? and password = ?";
		con = getConnect();
		pst = con.prepareStatement(sql);
		pst.setString(1, name);
		pst.setString(2, passwd);
		rSet = pst.executeQuery();
		if (rSet.next()) {
			return true;
		}
		return false;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPasswd() {
		return userPasswd;
	}

	public void setUserPasswd(String userPasswd) {
		this.userPasswd = userPasswd;
	}

	@Override
	public String toString() {
		return "userName=" + userName + ", userPasswd=" + userPasswd;
	}

}
